<?php

namespace App\Controllers;

use Laravel\Lumen\Routing\Controller;
use App\Providers\MyUserProvider;

class BaseController extends Controller
{
    /**
     * 不需要鉴权
     * 
     * @var array
     */
    public $allows = [];

    /**
     * 试玩用户
     * 
     * @var array
     */
    public $demos = [];

    /**
     * 代理用户
     * 
     * @var array
     */
    public $agents = [];

    public function __construct()
    {
        // Demo试玩账户权限验证
        $this->middleware('auth:' . MyUserProvider::USER_TYPE_DEMO, ['only' => $this->demos]);
        // 代理账户权限验证
        $this->middleware('auth:' . MyUserProvider::USER_TYPE_AGENT, ['only' => $this->agents]);
        // 默认所有接口都需要认证
        $this->middleware('auth', ['except' => array_merge($this->allows, $this->demos, $this->agents)]);
    }
}
